package 晚间作业0308;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Doc03_05 {

    public static void main(String[] args) {
        int year1 = 1991, month1 = Calendar.JANUARY, day1 = 31;
        int year2 = 2000, month2 = Calendar.NOVEMBER, day2 = 1;
        int interval = getIntervalOfDay(year1, year2, month1 + 1, month2 + 1, day1, day2);
        System.out.println("interval ==>" + interval);
        Calendar calendar = Calendar.getInstance();
        calendar.set(year1, month1, day1);
        calendar.add(Calendar.DATE, interval);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(format.format(calendar.getTime()));

        System.out.println(getFibonacci(3));

        drinkGame();
    }

    //文档day03-实战案例二：利用switch实现一个计算器操作

    //文档day03-课后作业
    /*
    1、x=2，y=0
    2、
    a=3 b=9 c=8
    a=3 b=10 d=10
    a=4 b=10 e=3
    a=5 b=10 f=5
    3、无结果
    4、if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
    5、略
    6、i=14
    7、x=2，y=0
     */
    //8、求出1〜100之间，即是3又是7的倍数出现的次数？
    private static void p08() {
        for (int i = 1; i <= 100; i++) {
            if (i % 3 == 0 && i % 7 == 0) {
                System.out.print(i + "\t");
            }
        }
    }

    //文档day04-课后作业
    /*
    5、i=1，j=-1
     */

    //文档day05-课后作业1,6题
    //1、设计方法，计算两个日期之间相差多少天。两个日期的年月日由参数控制
    public static int getIntervalOfDay(int year1, int year2,
                                       int month1, int month2,
                                       int day1, int day2) {
        int total = 0;
        //计算从year1的第一天到year2的第一天有多少天
        for (int y = year1; y < year2; y++) {
            total += getDaysOfYear(y);
        }
        //计算month1-day1到年初的天数，从总数中减去
        for (int m = 1; m < month1; m++) {
            total -= getDaysOfMonth(year1, m);
        }
        total -= day1;
        //计算month2-day2到年初的天数，加入到总数中
        for (int m = 1; m < month2; m++) {
            total += getDaysOfMonth(year2, m);
        }
        total += day2;
        return total;
    }

    public static int getDaysOfMonth(int year, int month) {
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                return 31;
            case 2:
                return isDeapYear(year) ? 29 : 28;
            default:
                return 30;
        }
    }

    public static boolean isDeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }

    public static int getDaysOfYear(int year) {
        return isDeapYear(year) ? 366 : 365;
    }

    //6、 使用递归输出30位的斐波那契数列
    public static int getFibonacci(int number) {
        if (number == 1 || number == 2) {
            return 1;
        } else
            return getFibonacci(number - 1) + getFibonacci(number - 2);
    }

    //过七，行酒令
    public static void drinkGame() {
        for (int i = 1; i <= 100; i++) {
            if ((i + "").contains("7")) {
                continue;
            }
            System.out.print(i + "\t");
        }
    }
}